<template>
    <div>
        <van-nav-bar title="我的地址" left-arrow @click-left="fun">
            <template #right>
                <van-icon name="ellipsis" size="26" />
            </template>
        </van-nav-bar>
        <van-address-list v-model="chosenAddressId" :list="list" default-tag-text="默认" @add="onAdd" @edit="onEdit" />
    </div>
</template>

<script>
import axios from 'axios';
let service = axios.create()
export default {
    data() {
        return {
            chosenAddressId: '1',
            list: [

            ],

        };
    },
    methods: {
        onAdd() {     //跳转至添加地址页面
            this.$router.push('/addaddress')
        },
        onEdit(item) {                 //跳转至编辑页面，并传给编辑页面初始值
            // console.log(item)
            this.$router.push({
                path: '/editaddress',
                query: {
                    txt: item
                }
            })
        },
        fun(){
            this.$router.push('/setting')
        }

    },
    mounted() {
        service({             //渲染前发送请求，响应显示所有地址
            url: "http://localhost:3000/address",
            method: "get"
        }).then(res => {
            // console.log(res.data)
            res.data.forEach(element => {
                element.address = element.addressDetail
                // delete element.address;
            });
            this.list = res.data
        })

    }
}
</script>

<style>

</style>